﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Guline.Web.Central.Controllers;
using Guline.Web.CentralModels.Object;
namespace Guline.Web.Central.Areas.Api.Controllers
{
    public class DeviceController : BaseController
    {
        public ActionResult SignIn(string Type, string ID, int AccountID, string AndroidName, string PhoneNumber)
        {
            if (Type == "android")
            {
                var dv = db.Devices.Where(m => m.AndroidID == ID).FirstOrDefault();
                if (dv == null)
                {
                    dv = new Device();
                    dv.Status = 1;
                    dv.Name = AndroidName;
                    dv.AccountID = AccountID;
                    dv.AndroidID = ID;
                    dv.DateCreated = DateTime.Now;
                    dv.DateLastedOnline = DateTime.Now;
                    dv.Enable = true;
                    dv.PhoneNumber = PhoneNumber;
                    db.Devices.Add(dv);
                }
                else
                {
                    dv.Status = 1;
                }
                db.SaveChanges();
                return Json(new { success = true }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { success = false }, JsonRequestBehavior.AllowGet);
            }

        }
        public ActionResult SignOut(string Type, string ID)
        {
            if (Type == "android")
            {
                var dv = db.Devices.Where(m => m.AndroidID == ID).FirstOrDefault();
                dv.Status = 0;
                db.SaveChanges();
                return Json(new { success = true }, JsonRequestBehavior.AllowGet);

            }
            else
            {
                return Json(new { success = false }, JsonRequestBehavior.AllowGet);
            }
             
        }
    }
}
